home *** CD-ROM | disk | FTP | other *** search
/ Space Shuttle - The First 100 Flights / Space Shuttle - The First 100 Flights.iso / xTras / DirectMedia Xtra Behaviors.cst / 00009_Script_Rate slider < prev    next >
Text File  |  2000-01-16  |  6KB  |  169 lines

  1. -- DirectMedia Xtra Rate Slider
  2.  
  3.  
  4.  
  5.  
  6. property pDuration, pMovieTime, VideoSprite
  7.  
  8. property extentSprite
  9. property hiliteMember  -- looks like the handle plus hilite graphics
  10. -- also holds the member of handle while hilited
  11.  
  12. property tracking
  13. property newLocH
  14. property newLocV
  15.  
  16. property dynamic   -- if true and sending true, sends value while tracking
  17.  
  18. property min, max  -- the range the slider maps to
  19. property valrange  -- the difference of max and min, set on begin
  20. property minScreen, maxScreen -- calculated from the screen coords of the extent
  21. property currentScreenVal -- the data point in screen coords, set in tracking
  22. property extentlength -- in screen coords, set on begin
  23.  
  24. property CurrentVal
  25.  
  26. on getPropertyDescriptionList
  27.   if the currentspritenum = 0 then 
  28.     set memdefault = 0 
  29.   else
  30.     set memref = the member of sprite the currentspritenum
  31.     set castlibnum = the castlibnum of memref
  32.     set memdefault = member (the membernum of member memref + 1)
  33.   end if
  34.   
  35.   
  36.   set description = [:]
  37.   
  38.   addprop description, #VideoSprite, [#default: 1, #format:#integer, #comment: "Video Sprite:"]
  39.   
  40.   addprop description, #extentSprite, [#default: 1, #format:#integer, #comment: "Extent Sprite:"]
  41.   
  42.   addprop description, #hiliteMember, [#default: memdefault , #format:#graphic,#comment: "Hilite Member:"]
  43.    
  44.   addprop description, #dynamic, [#default: 1, #format:#boolean,#comment: "Dynamic:"]
  45.   
  46.   return description
  47. end
  48.  
  49. on getBehaviorDescription
  50.   return "Drag to slider 'handle' to enable control of video rate.  Requires additional 'extent' member which limits the handle travel range." & RETURN & "PARAMETERS:" & RETURN & "ò Video Sprite - Enter the number of sprite channel in which video is displayed." & RETURN & "ò Extent Sprite -  Enter the number of sprite channel that contains the 'extent' sprite."  & RETURN & "ò Hilite Member -  Member to display while handle is being dragged."  & RETURN & "ò Dynamic - If set, video time will be updated while handle is dragged, else when handle is released."
  51. end
  52.  
  53. on compute_val me
  54.   -- relies on tracking to update the currentScreenVal (different for Hor, Vert)
  55.   set val = 0.0
  56.   set val = float(the currentScreenVal of me) / float (the extentlength of me)
  57.   set val = val * the valrange of me
  58.   set val = val + the min of me
  59.   return val
  60. end
  61.  
  62. on send_the_val me, val
  63.   -- sets the digital video volume to the val * paramter 
  64.   set pMovieTime = val * pDuration
  65.   setrate(sprite VideoSprite, pMovieTime)
  66. end
  67.  
  68.  
  69. on beginSprite me
  70.   
  71.   set pDuration = 200
  72.   
  73.   set the min of me = 0.0
  74.   set the max of me = 1.0
  75.  
  76.   set handle = the spritenum of me
  77.   set the tracking of me = FALSE
  78.   set the newLocH of me = the locH of sprite handle
  79.   set the newLocV of me = the locV of sprite handle
  80.   
  81.     set the newLocV of me = the locV of sprite the extentSprite of me
  82.     set the minScreen of me = the left of sprite the extentSprite of me
  83.     set the maxScreen of me = the right of sprite the extentSprite of me
  84.   
  85.   set the locH of sprite handle to the newLocH of me
  86.   set the locV of sprite handle to the newLocV of me
  87.   
  88.   set the valrange of me = the max of me - the min of me
  89.   set the extentlength of me = the maxScreen of me - the minScreen of me
  90.    
  91. end
  92.  
  93. on prepareFrame me
  94.   -- limits motion of handle to extents of extentSprite
  95.   -- and locks the handle to the track of the extentSprite
  96.   
  97.   if tracking then
  98.     set handle = the spriteNum of me
  99.     set extent =  the extentSprite of me
  100.     
  101.       set the newLocH of me = the mouseH
  102.       set the newLocV of me = the locV of sprite extent
  103.       if the newLocH of me < the left of sprite extent then
  104.         set the newLocH of me = the left of sprite extent
  105.       end if
  106.       if the newLocH of me > the right of sprite extent then
  107.         set the newLocH of me = the right of sprite extent
  108.       end if
  109.       
  110.       set the currentScreenVal of me = the newLocH of me - the minScreen of me
  111.       
  112.     set the locH of sprite handle to the newLocH of me
  113.     set the locV of sprite handle to the newLocV of me
  114.     
  115.     if the dynamic of me then
  116.       send_the_val me, compute_val (me)
  117.     end if
  118.     
  119.   else   --  end if tracking, control slider position by movieTime
  120.     
  121.     set x = float(getrate(sprite VideoSprite))/ float(pDuration)   
  122.     
  123.     set handle = the spriteNum of me
  124.     set extent =  the extentSprite of me
  125.     
  126.       set ScreenX = the left of sprite extent + (x * (the right of sprite extent - the left of sprite extent))
  127.       set the newLocH of me = screenX
  128.       set the newLocV of me = the locV of sprite extent
  129.       if the newLocH of me < the left of sprite extent then
  130.         set the newLocH of me = the left of sprite extent
  131.       end if
  132.       if the newLocH of me > the right of sprite extent then
  133.         set the newLocH of me = the right of sprite extent
  134.       end if
  135.       
  136.       set the currentScreenVal of me = the newLocH of me - the minScreen of me
  137.     
  138.     set the locH of sprite handle to the newLocH of me
  139.     set the locV of sprite handle to the newLocV of me
  140.     
  141.   end if
  142. end
  143.  
  144. on mouseDown me 
  145.   set tracking = TRUE
  146.   set temp = the member of sprite the spritenum of me
  147.   set the member of sprite the spritenum of me = member the hiliteMember of me
  148.   set the hiliteMember of me = temp
  149. end
  150.  
  151. on mouseUp me
  152.   set tracking = FALSE
  153.   set temp = the member of sprite the spritenum of me
  154.   set the member of sprite the spritenum of me = member the hiliteMember of me
  155.   set the hiliteMember of me = temp
  156.   
  157. end
  158.  
  159. on mouseUpOutside me
  160.   set tracking = FALSE
  161.   set temp = the member of sprite the spritenum of me
  162.   set the member of sprite the spritenum of me = member the hiliteMember of me
  163.   set the hiliteMember of me = temp
  164.   
  165. end
  166.  
  167.  
  168.  
  169.